package com.sinopec.yelofixedreader.uhf

import android.text.TextUtils

/**
 * lwj at 2023/5/22
 * 以前代码里面的判断规则不全
 */
object PalletCode {

    /**
     * lwj at 2023/5/22
     * 是否匹配该规则
     */
    fun validationRfidRule(
        code: String,
        rfid_regex: Regex,
    ): Boolean {
        if (TextUtils.isEmpty(code)) {
            return false
        }
        val replace = code.replace(" ", "")
        return replace.matches(rfid_regex)
    }

    /**
     * lwj at 2023/5/22
     * 从里面截取
     */
    fun getScanCode(scanCode: String): String? {
        //截取前12位，开头为86
        val substring: String = if (scanCode.startsWith("86")
            || scanCode.startsWith("87")
            || scanCode.startsWith("F6")
            || scanCode.startsWith("f6")
        ) {
            scanCode.substring(0, 17)
        } else if(scanCode.length > 18) {
            scanCode.substring(18)
        }else{
            ""
        }
        return substring
    }
}